import request from "@/utils/request";

// 文章相关API
const API = {
  GET_ARTICLE_LIST: "/home/articles", // 获取文章列表
  GET_HOT_ARTICLE_LIST: "/home/hotArticles", // 获取热门文章列表
  GET_USER_ARTICLE_LIST: "/user/getArticleList", //获取用户文章列表
  GET_USER_HOT_ARTICLE_LIST: "/user/hotArticles", //获取用户热门文章列表
  POST_PASSAGE: "/article/newOrUpdateArticle", // 新增文章
  GET_PASSAGE_BY_ID: "/article/getArticleContent",  //根据文章id获取文章
  DEL_PASSAGE: "/article/deleteArticle",//删除文章
  GET_PASSAGE_BY_CLASS: "/home/getArticlesByCategory",//根据分类获取文章
  ADD_VIEW: "/user/addWatch", // 增加文章浏览量
  ADD_LIKE: "/user/giveLike", // 增加文章点赞量
  HOME_SEARCH: "/home/search", // 首页搜索
  USER_SEARCH: "/user/search", // 用户文章搜索
  SEARCH_BY_TAG: "/user/searchTitleByTag", // 标签搜索
  GET_FOLLOW_ARTICLE_LIST: "/home/getFollowedArticles", // 获取关注文章列表
}

// 获取文章列表接口
export const reqGetArticleList = (userId) => request.get(API.GET_ARTICLE_LIST + `?userId=${userId}`);

// 获取热门文章列表接口
export const reqGetHotArticleList = (params) => request.get(API.GET_HOT_ARTICLE_LIST + `/${params}`);

// 获取用户文章列表接口
export const reqGetUserArticleList = (params) => request.get(API.GET_USER_ARTICLE_LIST + `?page=${params.page}&userId=${params.userId}`);

// 获取用户热门文章列表接口
export const reqGetUserHotArticleList = (params) => request.get(API.GET_USER_HOT_ARTICLE_LIST + `?userId=${params.userId}&num=${params.num}`);

//  新增文章接口
export const reqPostPassage = (params) => request.post(API.POST_PASSAGE, params);

//  根据文章id获取文章接口
export const reqGetPassageById = (passageId) => request.get(API.GET_PASSAGE_BY_ID + `?id=${passageId}`);

//删除文章接口
export const reqDelPassage = (passageId) => request.delete(API.DEL_PASSAGE + `?id=${passageId}`);

//根据分类获取文章接口
export const reqGetPassageByClass = (params) => request.get(API.GET_PASSAGE_BY_CLASS + `?category=${params.categoryName}&page=${params.page}`);


// 增加文章浏览量接口
export const reqAddView = (params) => request.post(API.ADD_VIEW + `?id=${params.userId}&passageId=${params.passageId}`);

// 增加文章点赞量接口
export const reqAddLike = (params) => request.post(API.ADD_LIKE + `?id=${params.userId}&passageId=${params.passageId}`);


// 首页搜索接口
export const reqHomeSearch = (params) => request.get(API.HOME_SEARCH + `?keyword=${params.keyword}&page=${params.page}`);

// 用户文章搜索接口
export const reqUserSearch = (params) => request.get(API.USER_SEARCH + `?keyword=${params.keyword}&page=${params.page}`);

// 标签搜索接口
export const reqSearchByTag = (params) => request.get(API.SEARCH_BY_TAG + `?tagName=${params.tag}&page=${params.page}&userId=${params.userId}`);

// 获取关注文章列表接口
export const reqGetFollowArticleList = (userId) => request.get(API.GET_FOLLOW_ARTICLE_LIST + `?userId=${userId}`);